<?php

/**
 * @Project NUKEVIET 3.0
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @Copyright (C) 2010 VINADES., JSC. All rights reserved
 * @Createdate 3/9/2010 23:25
 */

if ( ! defined( 'NV_IS_MOD_DOWNLOAD' ) ) die( 'Stop!!!' );

global $db, $module_name, $module_data, $module_info, $module_file, $lang_module, $list_cats;

$path = NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file ;
if ( ! file_exists( NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file  . '/block_topdownload.tpl' ) )
{
    $path = NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/" . $module_file ;
}

$xtpl = new XTemplate( "block_topdownload.tpl", $path);
$xtpl->assign( 'LANG', $lang_module );
//$query = "SELECT catid, title, alias, download_hits, fileupload FROM `" . NV_PREFIXLANG . "_" . $module_data . "` ORDER BY download_hits DESC LIMIT 5";
//Truongtt Edit
$query = "SELECT `m`.`id`, `m`.`catid`, `n`.`alias` as theloai, `m`.`title`, `m`.`alias`, `m`.`fileupload`
			FROM `" . NV_PREFIXLANG . "_" . $module_data . "` as `m` ,
			`" . NV_PREFIXLANG . "_" . $module_data . "_categories` as `n`
			WHERE `m`.`catid` = `n`.`id`
			ORDER BY RAND() DESC LIMIT 5";
$result = $db->sql_query( $query );
$i = 1;
while ( $row = $db->sql_fetchrow( $result ) )
{
	//Tên của thể loại Tài liệu (Tai-lieu, van-ban-lien-quan, bao-cao)
    $catalias = $list_cats[$row['catid']]['alias'];
    //Tên File
    $TenFile = $row['fileupload'];
    //Cắt xâu
    $TenFile = explode("/", $TenFile);
    //Lấy tên file
    $TenFile= $TenFile[3];
    //Lấy filetype
	$FileType = explode(".", $TenFile);
	$FileType = $FileType[1];
	//Lấy tên fileu pload
	$sFileName = $row['alias'];
	//Đổi ký tự "-" thành ký tự "_"
	$sFileName = preg_replace("/-/", "_",$sFileName);
    //$row['link'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $catalias . '/' . $row['alias'];
    $row['link'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=down&file=" . $sFileName.".".$FileType;
    $row['order'] = $i;
    $xtpl->assign( 'loop', $row );
    $xtpl->parse( 'main.loop' );
    $i ++;
}
$xtpl->parse( 'main' );
$content = $xtpl->text( 'main' );

?>